<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="id" prop="ID">
        <el-input
          v-model="queryParams.ID"
          placeholder="请输入id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="lot_id" prop="晶圆批次ID">
        <el-input
          v-model="queryParams.晶圆批次ID"
          placeholder="请输入lot_id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="production_type" prop="产品类型ID">-->
<!--        <el-input-->
<!--          v-model="queryParams.产品类型ID"-->
<!--          placeholder="请输入production_type"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="process_facility" prop="加工设备ID">-->
<!--        <el-input-->
<!--          v-model="queryParams.加工设备ID"-->
<!--          placeholder="请输入process_facility"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="mask_id" prop="掩膜版ID">-->
<!--        <el-input-->
<!--          v-model="queryParams.掩膜版ID"-->
<!--          placeholder="请输入mask_id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="process_" prop="加工状态">-->
<!--        <el-input-->
<!--          v-model="queryParams.加工状态"-->
<!--          placeholder="请输入process_"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="tech_id" prop="工艺编号">-->
<!--        <el-input-->
<!--          v-model="queryParams.工艺编号"-->
<!--          placeholder="请输入tech_id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="operation_number" prop="工序编号">-->
<!--        <el-input-->
<!--          v-model="queryParams.工序编号"-->
<!--          placeholder="请输入operation_number"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="process_stage" prop="加工阶段">-->
<!--        <el-input-->
<!--          v-model="queryParams.加工阶段"-->
<!--          placeholder="请输入process_stage"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="enter_time" prop="进入时间">-->
<!--        <el-input-->
<!--          v-model="queryParams.进入时间"-->
<!--          placeholder="请输入enter_time"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="departure_time" prop="离开时间">-->
<!--        <el-input-->
<!--          v-model="queryParams.离开时间"-->
<!--          placeholder="请输入departure_time"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="processing_area" prop="加工区域">-->
<!--        <el-input-->
<!--          v-model="queryParams.加工区域"-->
<!--          placeholder="请输入processing_area"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="priority" prop="优先级">-->
<!--        <el-input-->
<!--          v-model="queryParams.优先级"-->
<!--          placeholder="请输入priority"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="others" prop="备注">-->
<!--        <el-input-->
<!--          v-model="queryParams.备注"-->
<!--          placeholder="请输入others"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['flexiblescheduling:WIPs_info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['flexiblescheduling:WIPs_info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['flexiblescheduling:WIPs_info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['flexiblescheduling:WIPs_info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="WIPs_infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="ID" />
      <el-table-column label="lot_id" align="center" prop="晶圆批次ID" />
      <el-table-column label="production_type" align="center" prop="产品类型ID" />
      <el-table-column label="process_facility" align="center" prop="加工设备ID" />
      <el-table-column label="mask_id" align="center" prop="掩膜版ID" />
      <el-table-column label="process_" align="center" prop="加工状态" />
      <el-table-column label="tech_id" align="center" prop="工艺编号" />
      <el-table-column label="operation_number" align="center" prop="工序编号" />
      <el-table-column label="process_stage" align="center" prop="加工阶段" />
      <el-table-column label="enter_time" align="center" prop="进入时间" />
      <el-table-column label="departure_time" align="center" prop="离开时间" />
      <el-table-column label="processing_area" align="center" prop="加工区域" />
      <el-table-column label="priority" align="center" prop="优先级" />
      <el-table-column label="others" align="center" prop="备注" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['flexiblescheduling:WIPs_info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['flexiblescheduling:WIPs_info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改在制品信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="id" prop="ID">
          <el-input v-model="form.ID" placeholder="请输入id" />
        </el-form-item>
        <el-form-item label="lot_id" prop="晶圆批次ID">
          <el-input v-model="form.晶圆批次ID" placeholder="请输入lot_id" />
        </el-form-item>
        <el-form-item label="production_type" prop="产品类型ID">
          <el-input v-model="form.产品类型ID" placeholder="请输入production_type" />
        </el-form-item>
        <el-form-item label="process_facility" prop="加工设备ID">
          <el-input v-model="form.加工设备ID" placeholder="请输入process_facility" />
        </el-form-item>
        <el-form-item label="mask_id" prop="掩膜版ID">
          <el-input v-model="form.掩膜版ID" placeholder="请输入mask_id" />
        </el-form-item>
        <el-form-item label="process_" prop="加工状态">
          <el-input v-model="form.加工状态" placeholder="请输入process_" />
        </el-form-item>
        <el-form-item label="tech_id" prop="工艺编号">
          <el-input v-model="form.工艺编号" placeholder="请输入tech_id" />
        </el-form-item>
        <el-form-item label="operation_number" prop="工序编号">
          <el-input v-model="form.工序编号" placeholder="请输入operation_number" />
        </el-form-item>
        <el-form-item label="process_stage" prop="加工阶段">
          <el-input v-model="form.加工阶段" placeholder="请输入process_stage" />
        </el-form-item>
        <el-form-item label="enter_time" prop="进入时间">
          <el-input v-model="form.进入时间" placeholder="请输入enter_time" />
        </el-form-item>
        <el-form-item label="departure_time" prop="离开时间">
          <el-input v-model="form.离开时间" placeholder="请输入departure_time" />
        </el-form-item>
        <el-form-item label="processing_area" prop="加工区域">
          <el-input v-model="form.加工区域" placeholder="请输入processing_area" />
        </el-form-item>
        <el-form-item label="priority" prop="优先级">
          <el-input v-model="form.优先级" placeholder="请输入priority" />
        </el-form-item>
        <el-form-item label="others" prop="备注">
          <el-input v-model="form.备注" placeholder="请输入others" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWIPs_info, getWIPs_info, delWIPs_info, addWIPs_info, updateWIPs_info } from "@/api/flexiblescheduling/WIPs_info";

export default {
  name: "WIPs_info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 在制品信息表格数据
      WIPs_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ID: null,
        晶圆批次ID: null,
        产品类型ID: null,
        加工设备ID: null,
        掩膜版ID: null,
        加工状态: null,
        工艺编号: null,
        工序编号: null,
        加工阶段: null,
        进入时间: null,
        离开时间: null,
        加工区域: null,
        优先级: null,
        备注: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询在制品信息列表 */
    getList() {
      this.loading = true;
      listWIPs_info(this.queryParams).then(response => {
        this.WIPs_infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        晶圆批次ID: null,
        产品类型ID: null,
        加工设备ID: null,
        掩膜版ID: null,
        加工状态: null,
        工艺编号: null,
        工序编号: null,
        加工阶段: null,
        进入时间: null,
        离开时间: null,
        加工区域: null,
        优先级: null,
        备注: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ID)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加在制品信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.ID || this.ids
      getWIPs_info(ID).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改在制品信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ID != null) {
            updateWIPs_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWIPs_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const IDs = row.ID || this.ids;
      this.$modal.confirm('是否确认删除在制品信息编号为"' + IDs + '"的数据项？').then(function() {
        return delWIPs_info(IDs);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('flexiblescheduling/WIPs_info/export', {
        ...this.queryParams
      }, `WIPs_info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
